package com.azxcrm.project.system.customer.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.azxcrm.framework.web.controller.BaseController;
import com.azxcrm.framework.web.domain.Message;
import com.azxcrm.framework.web.page.TableDataInfo;
import com.azxcrm.project.system.customer.domain.CustomerClueDetail;
import com.azxcrm.project.system.customer.service.ICustomerClueDetailService;
import com.azxcrm.project.system.dict.domain.DictData;
import com.azxcrm.project.system.dict.service.IDictDataService;

/**
 * 客户线索详细问题分类 控制层处理
 * 
 * @author Dustyone
 * @date 2018-09-05
 */
@Controller       
@RequestMapping("/module/customerClueDetail")
public class CustomerClueDetailController extends BaseController
{
    private String prefix = "module/customerClueDetail";    
	
    /**
     * 字典常见问题类型
     */
	@Value("${crm.dictionary.question.type}")
	private String type;
	
	@Autowired
	private ICustomerClueDetailService customerClueDetailService;
	
	/**
	 * 常见问题类型
	 */
	@Autowired
	private IDictDataService dictDataService;
	
	@GetMapping()
	@RequiresPermissions("module:customerClueDetail:view")
	String customerClueDetail()
	{
	    return prefix + "/customerClueDetail";
	}
	
	/**
	 * 查询客户线索详细问题分类列表
	 */
	@GetMapping("/list")
	@RequiresPermissions("module:customerClueDetail:list")
	@ResponseBody
	public TableDataInfo list(CustomerClueDetail customerClueDetail)
	{
		setPageInfo(customerClueDetail);
        List<CustomerClueDetail> list = customerClueDetailService.selectCustomerClueDetailList(customerClueDetail);
		return getDataTable(list);
	}
	
	/**
	 * 新增客户线索详细问题分类
	 */
	@GetMapping("/add")
	@RequiresPermissions("module:customerClueDetail:add")
	public String add(DictData dictData,Model model)
	{
		dictData.setDictType(type);
		List<DictData> listdictData=dictDataService.selectDictDataList(dictData);
		model.addAttribute("listdictData", listdictData);
	    return prefix + "/add";
	}

	/**
	 * 修改客户线索详细问题分类
	 */
	@GetMapping("/edit/{detailId}")
	@RequiresPermissions("module:customerClueDetail:edit")
	public String edit(@PathVariable("detailId") Integer detailId,Model model)
	{	
		CustomerClueDetail customerClueDetail = customerClueDetailService.selectCustomerClueDetailById(detailId);
		model.addAttribute("customerClueDetail", customerClueDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存客户线索详细问题分类
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("module:customerClueDetail:save")
	public Message save(CustomerClueDetail customerClueDetail)
	{
		if (customerClueDetailService.saveCustomerClueDetail(customerClueDetail) > 0)
		{
			return Message.ok();
		}
		return Message.error();
	}
	
	/**
	 * 删除客户线索详细问题分类
	 */
	@PostMapping( "/remove/{detailId}")
	@ResponseBody
	@RequiresPermissions("module:customerClueDetail:remove")
	public Message remove(@PathVariable("detailId") Integer detailId)
	{
		if (customerClueDetailService.deleteCustomerClueDetailById(detailId) > 0)
		{
		    return Message.ok();
		}
		return Message.error();
	}
	
	/**
	 * 批量删除客户线索详细问题分类
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("module:customerClueDetail:batchRemove")
	public Message remove(@RequestParam("ids[]") Integer[] detailIds)
	{
		int rows = customerClueDetailService.batchDeleteCustomerClueDetail(detailIds);
		if (rows > 0)
        {
            return Message.ok();
        }
        return Message.error();
	}
	
	/**
	 * 字典常见问题大类对应子类集
	 */
	@GetMapping("/selectList")
	@ResponseBody
	public  List<CustomerClueDetail> selectList(CustomerClueDetail customerClueDetail)
	{
		List<CustomerClueDetail> list = customerClueDetailService.selectCustomerClueDetailList(customerClueDetail);
		return list;
	}
	
}
